﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace QQMusic.ViewModel.Base
{
    public class ViewModelBase : INotifyPropertyChanged, IDisposable
    {
        public event PropertyChangedEventHandler PropertyChanged;

        protected void OnPropertyChanged(string propertyName = null)
        {
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
        }

        public void Dispose()
        {
            this.Dispose(true);
            GC.SuppressFinalize(this);
        }

        private bool IsDisposed = false;

        /// <summary>
        /// 释放托管和非托管对象
        /// </summary>
        /// <param name="isDisposed"></param>
        protected virtual void Dispose(bool isDisposed)
        {
            if (this.IsDisposed) return;
            if (isDisposed)
            {
                // 释放那些实现IDisposable接口的托管对象
            }
            // 释放非托管资源，设置对象为null
            this.IsDisposed = true;
        }
    }
}
